package com.ctrip.cap.core.page;

import org.openqa.selenium.By;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

import com.ctrip.cap.appium.PopupUtils;
import com.ctrip.cap.appium.WaitUtils;
import com.ctrip.cap.page.CapPage;

public class HomePage extends CapPage<HomePage> {

	@FindBy(name = "机票")
	private WebElement flightNav;
	@FindBy(name = "酒店")
	private WebElement hotelNav;
	@FindBy(name = "火车票 · 欧铁")
	private WebElement trainNav;
	@FindBy(name = "团购")
	private WebElement groupBuyNav;
	@FindBy(name = "用车 · 自驾")
	private WebElement carNav;
	@FindBy(name = "汽车票")
	private WebElement busNav;
	@FindBy(name = "周末游")
	private WebElement weekendNav;
	@FindBy(name = "门票 · 玩乐")
	private WebElement ticketNav;
	@FindBy(name = "美食 · 购物")
	private WebElement foodNav;
	@FindBy(name = "旅游")
	private WebElement travelNav;
	@FindBy(name = "攻略 · 身边")
	private WebElement youNav;
	@FindBy(name = "礼品卡")
	private WebElement giftCardNav;
	@FindBy(name = "更多")
	private WebElement moreNav;

	@FindBy(id = "ctrip.android.view:id/myctrip")
	private WebElement myCtripNav;

	public HomePage(WebDriver driver) {
		super(driver);
	}

	public void toHotel() {
		hotelNav.click();
	}


	@Override
	protected void isLoaded() throws Error {
		// PopupUtils.ignoreUpdate(By.name("以后再说"), driver, 60); // 因为在首页所以时间特别长
		PopupUtils.ignoreUpdate(By.id("ctrip.android.view:id/lef_btn"), driver,
				20);
		WaitUtils.untilPageElementExist(myCtripNav);

		Point p = myCtripNav.getLocation();
		for (int i = 0; i < 4; i++) {
			driver.swipe(p.getX(), p.getY(), 100, p.getY(), 100);
		}
	}

	@Override
	protected void load() {

	}
}
